package com.lmf.controller;

import netscape.security.Principal;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.core.Authentication;
import org.springframework.security.oauth2.provider.OAuth2Authentication;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class IndexController {
    Logger logger= LoggerFactory.getLogger(IndexController.class);
    @GetMapping("/index")
    public String index(){
        logger.info("hello");
        return "欢迎";
    }

    @GetMapping("/hi")
    @PreAuthorize("hasAuthority('ROLE_ADMIN')")
    public String hi(){
        return "欢迎";
    }



    @RequestMapping("/getPrincipal")
    public OAuth2Authentication getPrinciple(OAuth2Authentication oauth2Authentication, Principal principal, Authentication authentication){
        System.out.println("====================================");
        System.out.println(oauth2Authentication);
        System.out.println(principal);
        System.out.println(authentication);
        System.out.println("====================================");
        return oauth2Authentication;
    }
}
